package com.yjy.fuyao.stu.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yjy.fuyao.stu.entity.Course;
import com.yjy.fuyao.stu.entity.Teacher;
import com.yjy.fuyao.stu.service.CourseService;
import com.yjy.fuyao.stu.service.TeacherService;
import com.yjy.fuyao.utils.result.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/stu/index")
public class IndexController {

    @Resource
    private CourseService courseService;

    @Resource
    private TeacherService teacherService;

    //查询前8条热门课程，查询前4条名师
    @ApiOperation(value = "查询前8条热门课程，查询前4条名师")
    @GetMapping("/")
    public R index() {
        //查询前8条热门课程
        LambdaQueryWrapper<Course> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Course::getStatus,"审核通过").orderByDesc(Course::getId).last("limit 8");
        List<Course> courseList = courseService.list(wrapper);

        //查询前4条名师
        QueryWrapper<Teacher> wrapperTeacher = new QueryWrapper<>();
        wrapperTeacher.orderByDesc("id");
        wrapperTeacher.last("limit 4");
        List<Teacher> teacherList = teacherService.list(wrapperTeacher);

        return R.ok().data("courseList",courseList).data("teacherList",teacherList);
    }
}
